package dome3;

public class Test3 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Student student1 = new Student("张三" , 10) ;
        Student student2  =(Student) student1.clone();
        student2.m.money = 888.88 ;
        System.out.println(student1);
        System.out.println(student2);
    }
}
    class  Money implements Cloneable{
        public double money = 9.99 ;

        @Override
        protected Object clone() throws CloneNotSupportedException {
            return super.clone();
        }
    }
    class  Student implements Cloneable{

        String name ;
        int age ;
        Money m ;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
        this.m = new Money() ;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
            Student tmp = (Student) super.clone();
              tmp.m = (Money) this.m.clone() ;
              return tmp ;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", m=" + m.money +
                '}';
    }
}
